#!/bin/bash

vip=172.16.1.166
vip_level=M
key=1
host_name=DB165
net_name=ens192
net_port=22

echo '--------------------------------------------------------------------------------' >> /u01/app/oracle/product/12.2.0/db_1/shell/log/vip_switch.log
current_ip=`ssh -p 22 root@${host_name} /sbin/ifconfig ${net_name}:$key | grep "inet" | awk '{ print $2 }'`
if [ "${current_ip}" = "${vip}" ]; then
    echo "current_ip is [${current_ip}] = [${vip}]"
        echo $(date "+%Y-%m-%d %H:%M:%S") "------------------- Enable ${host_name} ${vip_level} VIP NONE " >> /u01/app/oracle/product/12.2.0/db_1/shell/log/vip_switch.log
    exit 0;
else
    echo "current_ip is not [${current_ip}] !=[${vip}]"
    echo $(date "+%Y-%m-%d %H:%M:%S") "------------------- Enable ${host_name} ${vip_level} VIP Start." >> /u01/app/oracle/product/12.2.0/db_1/shell/log/vip_switch.log
    `ssh -p 22 root@${host_name} /sbin/ifconfig ${net_name}:${key} ${vip}/${net_port}`;
    #`ssh -p 10001 root@${host_name} /sbin/arping -I ${net_name} ${vip} -w 2`;
    echo $(date "+%Y-%m-%d %H:%M:%S") "------------------- Enable ${host_name} ${vip_level} VIP END..." >> /u01/app/oracle/product/12.2.0/db_1/shell/log/vip_switch.log
    exit 0;
fi

